package com.k1998.mybatis.controller;

import com.k1998.mybatis.bean.JxTimeTable;
import com.k1998.mybatis.service.JxTimeTableService;
import com.k1998.mybatis.utils.BatchInfo;
import com.k1998.mybatis.utils.QueryInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @Author: ChenYuxiang
 * @Description: //JxTimeTableController
 * @Param:
 * @return:
 * @Date: 17:09 2021/2/25
 **/

@RestController
@Api(value = "计协课程表API文档", tags = {"计协课程表API文档"})
public class JxTimeTableController {
    @Autowired
    JxTimeTableService service;

    @PostMapping("/findAllJxTimeTable")
    @ApiOperation(value = "筛选查询资源", notes = "display无用 使用query进行模糊查询 按照class_order 降序排列")
    public String getAllJxTimeTable(@RequestBody QueryInfo queryInfo) {
        return service.findAll(queryInfo);
    }

    @PostMapping("/detailJxTimeTable")
    @ApiOperation(value = "详细查询", notes = "仅id属性有效", httpMethod = "POST")
    public String detailJxTimeTable(@RequestBody JxTimeTable jxTimeTable) {
        return service.detail(jxTimeTable);
    }

    @PostMapping(value = "/deleteJxTimeTable")
    @ApiOperation(value = "批量删除资源信息", notes = "仅ids有效 多个id 用逗号隔开", httpMethod = "POST")
    public String deleteJxTimeTable(@RequestBody BatchInfo info) {
        return service.delete(info);
    }

    @PostMapping(value = "/insertJxTimeTable")
    @ApiOperation(value = "上传资源", notes = "id无效", httpMethod = "POST")
    public String insertJxTimeTable(@RequestParam(value = "file") MultipartFile multipartFile,
                                    @RequestParam(value = "className") String className,
                                    @RequestParam(value = "classOrder") Integer classOrder,
                                    @RequestParam(value = "remark") String remark) throws IOException {
        return service.insert(multipartFile, className, classOrder, remark);
    }

    @PostMapping(value = "/updateJxTimeTable")
    @ApiOperation(value = "更新资源", notes = "id无效", httpMethod = "POST")
    public String updateJxTimeTable(MultipartFile multipartFile,
                                    @RequestParam(value = "id") Integer id,
                                    @RequestParam(value = "className") String className,
                                    @RequestParam(value = "classOrder") Integer classOrder,
                                    @RequestParam(value = "remark") String remark) throws IOException {
        return service.update(multipartFile, id, className, classOrder, remark);
    }
}
